import 'dart:io';

class AppledocScript {
  Future<bool> env() async {
    var process = await Process.start('which', ['appledoc']);
    if (await process.stdout.isEmpty) {
      return false;
    }
    return true;
  }

  Future<bool> env_docsetutil() async {
    var process = await Process.start('which', ['docsetutil']);
    if (await process.stdout.isEmpty) {
      return false;
    }
    return true;
  }

  Future<void> appledoc(
    String proj,
    String company,
    String out,
    String input, {
    String company_id,
    String company_url,
    String target,
  }) async {
    var args = [
      '--project-name',
      proj,
      '--project-company',
      company,
      '--output',
      out,
      '--company-id',
      company_id,
      '--docset-atom-filename',
      '$company.atom',
      '--docset-feed-url',
      '$company_url/$company/%DOCSETATOMFILENAME',
      '--docset-package-url',
      '$company_url/$company/%DOCSETPACKAGEFILENAME',
      '--docset-fallback-url',
      '$company_url/$company',
      '-i',
      '*.m',
      '--publish-docset',
      '--docset-platform-family',
      target,
      '--logformat',
      'xcode',
      '--keep-intermediate-files',
      '--no-repeat-first-par',
      '--no-warn-invalid-crossref',
      '--exit-threshold',
      '2',
      input,
    ];

    await Process.start('appledoc', args);
  }
}
